﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>产品分类</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="/style/admin/style/adminStyle.css" rel="stylesheet" type="text/css" />
        <script src="/style/admin/js/jquery.js"></script>
    </head>
    <body>
        <div class="wrap">
            <div class="page-title">
                <span class="modular fl"><i></i><em>产品分类</em></span>
                <span class="modular fr"><a href="/admin/goods_category/create" class="pt-link-btn">+添加新分类</a></span>
            </div>

            <table class="list-style">
                <tr>
                    <th>分类名称</th>
                    <th>产品数量</th>
                    <th>单位</th>
                    <th>是否显示</th>
                    <th>排序</th>
                    <th>操作</th>
                </tr>
                @foreach($data as $value)
                <tr>
                    <td>
                        <input type="checkbox" class="ckb" value="{{$value->id}}"/>
                        <?php 
                           $arr=explode(",", $value->path);
                           $tot=count($arr);
                        ?>
                        <span>{{str_repeat("||===",$tot-2)}}{{$value->name}}</span>
                    </td>
                    <td class="center"></td>
                    <td class="center">{{$value->unit}}</td>
                    @if($value->is_show==1)
                    <td class="center"><img onclick="status(this,{{$value->id}},0)" src="/style/admin/images/yes.gif"/></td>
                    @else
                    <td class="center"><img onclick="status(this,{{$value->id}},1)" src="/style/admin/images/no.gif"/></td>
                    @endif
                    <td class="center"><input type="text" value="{{$value->sort}}" style="width:50px;text-align:center;"/></td>
                    <td class="center"> <a href="/admin/goods_category/{{$value->id}}" title="添加子分类">+</a>&nbsp;<a href="/admin/goods_category/{{$value->id}}/edit" title="修改"><img src="/style/admin/images/icon_edit.gif"/></a><a href="javascript::;" onclick="del({{$value->id}})" title="移除"><img src="/style/admin/images/icon_trash.gif"/></a></td>
                </tr> 
                @endforeach
            </table>

            <!-- BatchOperation -->
            <div style="overflow:hidden;">
                <!-- Operation -->
                <div class="BatchOperation fl">
                    <input type="checkbox" id="del" onclick="SelectAll()"/>
                    <label for="del" class="btnStyle middle">全选</label>
                    <input type="button" onclick="all_Del()" value="批量删除" class="btnStyle"/>
                </div>
                <!-- turn page -->
                <div class="turnPage center fr">
                    <a>第一页</a>
                    <a>1</a>
                    <a>最后一页</a>
                </div>
            </div>
        </div>
    </body>
    <script>
        //ajax批量删除
        function all_Del(){
            var ids=""
            $(".ckb").each(function(){
                if($(this).is(':checked')){
                     ids+=","+$(this).val();//把要删除的id拼接成字符串
                } 
            }) 
            ids = ids.substring(1); // 对id进行处理，去除第一个逗号 
            if(ids.length==0){
                alert("请选择要删除的分类");
            }else{
                if(confirm("确定删除？删除后将无法恢复。")){
                    $.post("/admin/goods/all_del",{"ids":ids,"_token":"{{csrf_token()}}","_method":"post"},function(data){
                        if(data==1){
                            window.location.reload();
                        }else{
                            alert(data);
                        }
                    })
                }
            } 
        }
        //全选或者全取消 
        function SelectAll(){ 
          $("#del").is(':checked')?$(".ckb").prop("checked",true):$(".ckb").prop("checked",false);  
        }
        //ajax改变是否显示状态
        function status(obj,id,is_show){
            if(is_show==1){
            $.post("/admin/goods/ExitStatus",{"id":id,"is_show":is_show,"_token":"{{csrf_token()}}"},function(data){
               if(data==1){
                   $(obj).parent().html('<img onclick="status(this,'+id+',0)" src="/style/admin/images/yes.gif"/>');
               }else{
                   alert(data);
               }
            })
        }else{
              $.post("/admin/goods/ExitStatus",{"id":id,"is_show":is_show,"_token":"{{csrf_token()}}"},function(data){
               if(data==1){
                   $(obj).parent().html('<img onclick="status(this,'+id+',1)" src="/style/admin/images/no.gif"/>');
               }else{
                   alert(data);
               }
            })  
            }
        }
        //ajax删除分类
        function del(id){
        var str = confirm("确定删除此分类吗?");
        if (str){
        $.post("/admin/goods_category/" + id, {"_token":"{{csrf_token()}}", "_method":"delete"}, function(data){
        if (data == 1){
        window.location.reload();
        } else{
        alert(data);
        }
        })
        }
        }
    </script>
</html>